<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // for ... of ... ES6语法
        // let arr = ["张三","李四","王五"];
        // console.log(arr);
        // for(let val of arr){
        //     console.log(val); // 数组每一项
        // }

        let arr = ["张三","李四","王五"];
    //     // 获取迭代器
    //     console.log(arr);
    //     // console.log( arr[Symbol.iterator]())
    //    let iter =  arr[Symbol.iterator]();
    //    console.log( iter.next());
    //    console.log( iter.next());
    //    console.log( iter.next());
    //    console.log( iter.next());

    function myiterator(arr){
        let num = 0;
        return {
            next(){
                return {
                    value:arr[num++],
                    done:num>arr.length?true:false
                }
            }
        }
    }


  let res =   myiterator(arr);
  console.log( res.next());
  console.log( res.next());
  console.log( res.next());
  console.log( res.next());







    </script>
</body>
</html>